<%@ page import="com.tlb.ejb.*,com.tlb.dto.*,com.tlb.web.*,java.util.*" %>
<%

Poster p = new AuthManager(request, response).hardAuthenticatePoster();


%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>Big<%=Util.getUtil().getBoard(request) == Util.BCB ? "College" : "Law"%>Board.com</title>
    <link rel="stylesheet" type="text/css" href="ext/tlbStyle.css" />
    <link rel="shortcut icon" href="ext/c_sailboat.gif">
    <script type="text/javascript" src="ext/ajax.js"></script>
    <script type="text/javascript" src="ext/tlbMenu.js" />
    <script type="text/javascript">
        window.onload = initLeftMenu;
    </script>
    
    <script>
        var psStat = 1;
        var mnStat = 1;
        
        function getCheckedValue(radioObj) {
            if(!radioObj)
                return "";
            var radioLength = radioObj.length;
            if(radioLength == undefined)
                if(radioObj.checked)
                    return radioObj.value;
                else
                    return "";
                for(var i = 0; i < radioLength; i++) {
                    if(radioObj[i].checked) {
                        return radioObj[i].value;
                    }
                }
                return "";
            }                
            
            function updateStat() {
                if(psStat == 0 && mnStat == 0) {
                    document.getElementById("formStat").innerHTML = "";
                }
            }
            
            function checkMoniker(form) {
                document.getElementById('monBtnNew').disabled=true;
                mnStat = 1;
                updateStat();
                sendAjax("action=regCheckMoniker&name=" + form.moniker.value, checkMonikerCB);
                document.getElementById('monStatusNew').innerHTML = "checking availability...";
                document.getElementById('monStatusNew').style.color="black";
            }
            
            function checkMonikerCB(respData) {
                if(respData.responseText.substring(0,1) == "1") {
                    document.getElementById('monStatusNew').innerHTML = "available!";
                    document.getElementById('monStatusNew').style.color="black";
                    document.getElementById('monBtnNew').disabled=false;
                    mnStat = 0;
                } else {
                document.getElementById('monStatusNew').innerHTML = respData.responseText;
                document.getElementById('monStatusNew').style.color="red";
                document.getElementById('monBtnNew').disabled=true;
                mnStat = 1;
            }
        }
        
        function chgPass(form) {
            if(psStat == 0) {
                sendAjax("action=chgPassword&password1=" + form.password1.value + "&password2=" + form.password2.value, chgPasswordCB);
            }
            document.getElementById('chgPassBtn').disabled=true;
            document.getElementById('password1').disabled=true;
            document.getElementById('password2').disabled=true;
        }
        
        function chgPasswordCB(respData) {
            if(respData.responseText.substring(0,1) == "1") {
                document.getElementById('passwordStatus').innerHTML = "Password Changed";
                document.getElementById('passwordStatus').style.color="black";
            } else {
            document.getElementById('passwordStatus').innerHTML = respData.responseText;
            document.getElementById('passwordStatus').style.color="red";
            document.getElementById('chgPassBtn').disabled=false;
            document.getElementById('password1').disabled=false;
            document.getElementById('password2').disabled=false;
            psStat = 1;
        }
        updateStat();
    }
    
    function chgReply(form) {
        sendAjax("action=chgReply&inlineReply=" + getCheckedValue(form.inlineReply), chgReplyCB);
        document.getElementById('chgReplyBtn').disabled=true;
    }
    
    function chgReplyCB(respData) {
        if(respData.responseText.substring(0,1) == "1") {
            document.getElementById('replyStatus').innerHTML = "Reply Style Changed";
            document.getElementById('replyStatus').style.color="black";
            document.getElementById('chgReplyBtn').disabled=false;
        } else {
        document.getElementById('replyStatus').innerHTML = respData.responseText;
        document.getElementById('replyStatus').style.color="red";
    }
    updateStat();
}



function chgFilt(form) {
    sendAjax("action=chgFilter&spam=" + form.spam.checked + "&offense=" + form.offense.checked, chgFiltCB);
    document.getElementById('chgFiltBtn').disabled=true;
    document.getElementById('filtStatus').innerHTML = "";
}

function chgFiltCB(respData) {
    if(respData.responseText.substring(0,1) == "1") {
        document.getElementById('filtStatus').innerHTML = "Filters Updated";
    } else {
        document.getElementById('filtStatus').innerHTML = "Error Saving Filters";
        document.getElementById('filtStatus').style.color="red";
    }
}

function editMon(form, monikerId) {
    sendAjax("action=chgMoniker&monikerId=" + monikerId + "&tag=" + eval("form.tag" + monikerId + ".value") + "&primMon=" + getCheckedValue(form.primMon) + "&showCounter=" + eval("form.showCounter" + monikerId + ".checked"), editMonCB);
    document.getElementById('monBtn' + monikerId).disabled=true;
}

function editMonCB(respData) {
    if(respData.responseText.substring(0,1) == "1") {
        document.getElementById('monStatus' + respData.responseText.substring(2, respData.responseText.length - 1)).innerHTML = "Moniker Edited";                        
    } else {
        alert("Error Editing Moniker");
    }
}


function saveMon(form) {
    document.getElementById('monBtnNew').disabled=true;
    if(mnStat != 0) {
        return;
    }
    sendAjax("action=addMoniker&name=" + form.moniker.value + "&tag=" + form.tag.value + "&primMon=" + getCheckedValue(form.primMon) + "&showCounter=" + form.showCounter.checked, saveMonCB);
    document.getElementById('monStatusNew').innerHTML = "saving...";
    document.getElementById('monStatusNew').style.color="black";
}

function saveMonCB(respData) {
    if(respData.responseText.substring(0,1) == "1") {
        document.getElementById('monStatusNew').style.color="black";
        document.getElementById('monStatusNew').innerHTML = "Moniker Created";
    } else {
    document.getElementById('monStatusNew').style.color="red";
    document.getElementById('monStatusNew').innerHTML = "Error Creating Moniker";
    document.getElementById('monBtnNew').disabled=false;
}
}


function checkPassword(form) {               
    if(form.password1.value == "" || form.password2.value == "") {
        document.getElementById('passwordStatus').innerHTML = "";
        psStat = 1;
        updateStat();
    } else if(form.password1.value != form.password2.value) {
        document.getElementById('passwordStatus').innerHTML = "passwords don't match";
        document.getElementById('passwordStatus').style.color="red";
        psStat = 1;
        updateStat();
    } else {
        psStat = 1;
        updateStat();
        sendAjax("action=regCheckPassword&name=" + form.password1.value, checkPasswordCB);
    }
}

function checkPasswordCB(respData) {
    if(respData.responseText.substring(0,1) == "1") {
        document.getElementById('passwordStatus').innerHTML = "";
        psStat = 0;
    } else {
        document.getElementById('passwordStatus').innerHTML = respData.responseText;
        document.getElementById('passwordStatus').style.color="red";
        psStat = 1;
    }
    updateStat();
}


    </script>
    
</head>

<body onload="initLeftMenu()">
<center>
<div id="mainContainer">
    
    <table>
        <tr>
            <td valign="top">
            <%@ include file="header.jsp" %>
            <br />
            <div id="contentContainer" style="background-color:#FFFFFF">
            
            
            <div id=registerDiv>
            <h1>Profile Settings</h1>
            
            <form action="registerAction.jsp" name="regForm" method=post>
            <table width=500 border=0 cellpadding="2" cellspacing="1">
                
                <tr>
                    <td colspan="3">
                        <h3>Your Login</h3>
                        <hr noshade>
                        <span style="color:#404040;font-size:13px">This login name is never shown to others - use it to access the site and manage content from each of your monikers.</span>
                    </td>
                </tr>
                <tr>
                    <td width=140><b>Username:</b></td>
                    <td width=140 colspan=2><%=p.getUserName()%></td>
                </tr>
                <tr>
                    <td><b>Change Password: </b></td>
                    <td><input type=password name=password1 id=password1 maxlength="12" onchange="checkPassword(this.form)" value=""></td>
                    <td><div id=passwordStatus></div></td>
                </tr>
                <tr>
                    <td><b>Re-Enter Password: </b></td>
                    
                    <td colspan="2"><input type=password id=password2 name=password2 maxlength="12" onchange="checkPassword(this.form)" value=""></td>
                </tr>
                <tr>
                    <td colspan=3><span id=chgPass><input id=chgPassBtn type=button value="Change Password" class=btn onclick="chgPass(this.form)"></span></td>
                </tr>
                
                <tr>
                    <td colspan="3">
                        <br>
                        <h3>Reply/Edit Style</h3>
                        <hr noshade>
                    </td>
                </tr>                
                <tr>
                    <td>
                        <input <%= p.getInlineReply() == 1 ? "checked" : "" %> type=radio name=inlineReply value=1>Inline (recommended)
                        <br>
                        <input <%= p.getInlineReply() == 0 ? "checked" : "" %> type=radio name=inlineReply value=0>Classic
                    </td>
                    <td colspan="2" valign=bottom><span id=replyStatus>&nbsp;</span></td>
                </tr>
                <tr>
                    <td colspan=3><span id=chgReply><input id=chgReplyBtn type=button value="Change Reply Style" class=btn onclick="chgReply(this.form)"></span></td>
                </tr>
            </table>
            <table width=500 border=0 cellpadding="2" cellspacing="1">
            <td colspan="3">
                <br><h3>Content Filter Settings</h3>
                <hr noshade>
                <span style="color:#404040;font-size:13px">Please read about our <a href="policies.jsp" target=new>community moderation</a> program.  As a registered user you can opt-in to view flagged content.</span>
            </td>
        </tr>
        <tr>
            <td colspan=3><input <%= !p.getNsfw() ? "" : "checked" %> type=checkbox id=offense name=offense value=1><b>Show Offensive Content - </b><span style="color:#404040;font-size:13px">(Content you wouldn't view at work or school.)</span></td>
        </tr>
        <tr>
            <td colspan=3><input <%= !p.getSpam() ? "" : "checked" %> type=checkbox id=spam name=spam value=1><b>Show Spam - </b><span style="color:#404040;font-size:13px">(Board cluttering content.)</span></td>
        </tr>
        <tr>
            <td colspan=3><span id=filtStatus></span><br><span id=chgFilter><input id=chgFiltBtn onclick="chgFilt(this.form)" type=button value="Update Filter Settings" class=btn></span></td>
        </tr>
    </table>
    <table width=600 border=0 cellpadding="2" cellspacing="1">
        <tr>
            <td colspan="4">
                <br />
                <h3>Manage Your Monikers</h3>
                <hr noshade>
                <span style="color:#404040;font-size:13px">One of your monikers is attached to any content you create.  Your monikers are not linked in any public areas.</span>
            </td>
        </tr>
        <tr>
            <td width=140 valign=top><b>Moniker</b></td>
            <td valign=top><b>Tagline</b></td>
            <td valign=top><b>Primary</b></td>
            <td valign=top><b>Post Count</b></td>
            <td valign=top>&nbsp;</td>
            <td valign=top>&nbsp;</td>
        </tr>
        
        <tr>
            <td width=140><%= p.getPrimaryMoniker().getName() %></td>
            <td width=150><input type=text name="tag<%=p.getPrimaryMoniker().getMonikerId()%>" maxlength="45" value="<%= p.getPrimaryMoniker().getTagLine() %>"></td>
            <td><input type="radio" name=primMon value="<%=p.getPrimaryMoniker().getMonikerId()%>" checked></td>
            <td><input type="checkbox" name=showCounter<%=p.getPrimaryMoniker().getMonikerId()%> value="true" <%=p.getPrimaryMoniker().getShowCounter()?"checked":""%>></td>
            <td><input type=button id="monBtn<%=p.getPrimaryMoniker().getMonikerId()%>" onclick="editMon(this.form, <%= p.getPrimaryMoniker().getMonikerId() %>)" class="btn" value=Update></td>
            <td width=140><span id="monStatus<%= p.getPrimaryMoniker().getMonikerId() %>"></span></td>
        </tr>
        
        <%
            Set mons = p.getMonikers();
            mons.remove(p.getPrimaryMoniker());
            if (mons.size() > 0) {
                for (Iterator it = mons.iterator(); it.hasNext();) {
                    Moniker mon = (Moniker) it.next();
                    if (mon.getName().equals("Guest")) {
                        continue;
                    }
        %>
        <tr>
            <td width=140><%=mon.getName()%></td>
            <td><input type=text name="tag<%=mon.getMonikerId()%>" maxlength="45" value="<%=mon.getTagLine()%>"></td>
            <td><input type="radio" name=primMon value="<%=mon.getMonikerId()%>"></td>
            <td><input type="checkbox" name=showCounter<%=mon.getMonikerId()%> value="true" <%=mon.getShowCounter()?"checked":""%>></td>
            <td><input id="monBtn<%=mon.getMonikerId()%>" type=button onclick="editMon(this.form, <%=mon.getMonikerId()%>)" class="btn" value=Update></td>
            <td><span id="monStatus<%= mon.getMonikerId() %>"></span></td>
        </tr>        
        <%
                }
            }
        %>
        <tr>
            <td colspan=4>&nbsp;</td>
        </tr>
        <tr>
            <td width=140><input type=text name=moniker maxlength="45" onchange="checkMoniker(this.form)"></td>
            <td><input type=text name=tag maxlength="45"></td>
            <td>&nbsp;</td>
            <td><input type="checkbox" name=showCounter value="true" checked></td>
            <td><input id=monBtnNew type=button onclick="saveMon(this.form)" class="btn" value="Save New" disabled=true></td>
            <td><span id="monStatusNew"></span></td>
        </tr>
        
        
    </table>
    <br><br><br>
    
    </form>
</div>

</div>
</td>
<td valign=top>
    
    <%@ include file="menu.jsp" %>
    
</td>
</tr>
</table>


</div>
<!-- Start of StatCounter Code -->
<script type="text/javascript">
    var sc_project=2753481; 
    var sc_invisible=0; 
    var sc_partition=27; 
    var sc_security="fadeb289"; 
    </script>
<script type="text/javascript" src="http://www.statcounter.com/counter/counter_xhtml.js"></script><noscript><div class="statcounter"><a class="statcounter" href="http://www.statcounter.com/"><img class="statcounter" src="http://c28.statcounter.com/2753481/0/fadeb289/0/" alt="blog stats" /></a></div></noscript>
<!-- End of StatCounter Code -->
</center>
</body>
</html>